﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.Collections;

namespace BlogManager
{
    public partial class FilterControl : UserControl
    {
        public FilterControl()
        {
            InitializeComponent();
            optModificati.Tag = FilterMode.Modificati;
            optNonModificati.Tag = FilterMode.NonModificati;
            optTutti.Tag = FilterMode.Tutti;
        }

        [AttributeProvider(typeof(IListSource)), DefaultValue((string)null), RefreshProperties(RefreshProperties.Repaint)]
        public object DataSource
        {
            get { return this.cmbFilter.DataSource; }
            set { this.cmbFilter.DataSource = value; }
        }

        public string DisplayMember
        {
            get { return this.cmbFilter.DisplayMember; }
            set { this.cmbFilter.DisplayMember = value; }
        }

        public string ValueMember
        {
            get { return this.cmbFilter.ValueMember; }
            set { this.cmbFilter.ValueMember = value; }
        }

        public event EventHandler<FilterEventArgs> FilterChanged;
        
        protected virtual void OnFilterChanged()
        {
            FilterEventArgs e = new FilterEventArgs(this.filterMode, this.filterItem);
            OnFilterChanged(e);
        }

        protected virtual void OnFilterChanged(FilterEventArgs e)
        {
            if (FilterChanged != null)
                FilterChanged(this, e);
        }

        private FilterMode filterMode = FilterMode.Tutti;
        [Browsable(false)]
        public FilterMode FilterMode
        {
            get { return filterMode; }
        }

        private void optTutti_CheckedChanged(object sender, EventArgs e)
        {
            RadioButton option = sender as RadioButton;
            if (option != null && option.Checked)
            {
                this.filterMode = (FilterMode)option.Tag;
                OnFilterChanged();
            }
        }

        private object filterItem = null;
        [Browsable(false)]
        public object FilterItem
        {
            get { return filterItem; }
        }

        private void cmbFilter_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cmbFilter.SelectedIndex == 0)
            {
                filterItem = null;
            }
            else
            {
                this.filterItem =
                    this.cmbFilter.SelectedItem;
            }

            OnFilterChanged();
        }

        public IList ModifiedItems { get; set; }

        public bool ToShow(
    }
}
